package gregorytersoff_controller;



import gregorytersoff_boundary.DecisionlinesGUI;
import gregorytersoff_boundary.LineCanvas;
import gregorytersoff_model.Model;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;




public class ChoiceController 
{
	private DecisionlinesGUI frame;
	private Model model;
	
	/**
	 * Checks whether any of the choice names are editable (indicating they have not passed the test given by the ChoiceNameController); if they
	 * are, it resets the error message text to the appropriate text, and if not, it allows the user to start adding edges after setting the lines
	 * in the model
	 * @param f the frame to check the choices of
	 * @param m the model to generate and lock in each Line of.
	 */
	public ChoiceController (DecisionlinesGUI f, Model m)
	{
		frame = f;
		model = m;
	}
	
	/**
	 * checks if the JTextFields are editable, and if so, tells the model to make each Line based on the text of those JTextFields, and otherwise
	 * sets the error message to inform the user that they need to lock in each choice name
	 */
	public void process()
	{
		boolean alldifferent = true;
		if(frame.checkFilled() == true)
		{
			for(int i = 0; i<frame.getChoiceText().length; i++)
			{
				if(frame.getChoiceText()[i].isEditable() == true)
					alldifferent = false;
			}
			if(alldifferent)
			{
				String[] answers = frame.lockChoices();
				model.setLines(answers);
				new ErrorController("Any errors will appear here", frame).process();
			}
			else
			{
				new ErrorController("Lock in all choices in order to begin", frame).process();
			}
		}
		else
		{
			new ErrorController("Fill in and lock in all choices in order to begin", frame).process();
		}
	}
	

}
